package com.zcoj.service.impl;

import com.zcoj.pojo.Dto.Discussion;
import com.zcoj.pojo.Dto.Judge;
import com.zcoj.pojo.Dto.User;
import com.zcoj.service.DiscussionService;
import com.zcoj.service.JudgerService;
import com.zcoj.service.SystemInfoService;
import com.zcoj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author chenbin
 * @version 1.0
 * @description: TODO
 * @date 2023/5/23 12:33
 */
@Service
public class SystemInfoServiceImpl implements SystemInfoService {

    @Autowired
    private UserService userService;

    @Autowired
    private JudgerService judgerService;

    @Autowired
    private DiscussionService discussionService;

    @Override
    public Map<String, Integer> getAdminHomeData() {
        Integer userNumber = Math.toIntExact(userService.count(new User()));
        Integer submitNumber = Math.toIntExact(judgerService.count(new Judge()));
        Judge judge = new Judge();
        judge.setStatus(1);
        Integer accessNumber = Math.toIntExact(judgerService.count(judge));
        Integer discussionNumber = Math.toIntExact(discussionService.count(new Discussion()));

        Map<String, Integer> map=new HashMap<>();
        map.put("userNumber",userNumber);
        map.put("submitNumber",submitNumber);
        map.put("accessNumber",accessNumber);
        map.put("discussionNumber",discussionNumber);
        return map;
    }
}
